//
//  MSRoomManagementController.m
//  觅尚
//
//  Created by No.8 on 2019/3/27.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSCaiwuController.h"
#import "MSBindingRelationsCell.h"
#import "MSRoomConsumptionController.h"
#import "MSRoomManageMentModel.h"
#import "MSQueryRelationsController.h"
#import "MSSetRoomManagementController.h"
#import "ScanningViewController.h"
#import "MSFinancialRoomManagementController.h"
#import "MSRoomHousesListController.h"
#import "MSMyModel.h"

#define pageSize 4

// 注意const的位置
static NSString *const cellId = @"cellId";
static NSString *const headerId = @"headerId";
static NSString *const footerId = @"footerId";

@interface MSCaiwuController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,MSBindingRelationsCellDelegate>
{
    CustomNavigationBar *naviagtionBar;
    NSUInteger page;
    NSUInteger count;
}
/** <#name#>*/
@property(nonatomic,strong)MSRoomManageMentModel *ManageMentModel;

/** tableview */
@property (strong,nonatomic)UICollectionView * CollectionView;

/** 头部视图 */
@property(strong,nonatomic)UIView *CollectionHeaderView;

/** 数组*/
@property(nonatomic,strong)NSMutableArray *RoomManagementArray;

/** 数组*/
@property(nonatomic,strong)NSMutableDictionary *RoomArray;
/** 房间id*/
@property(nonatomic,strong)NSString *roomid;

/** 房间名称*/
@property(nonatomic,strong)NSString *RoomName;

/** 操作人ID*/
@property(nonatomic,strong)NSString *RoomUid;

/** 操作人ID*/
@property(nonatomic,strong)NSString *RoomMoney;


/** 遮盖层*/
@property(nonatomic,strong)UIView *backView;


/** 弹出View*/
@property(nonatomic,strong)UIView *showView;


/** 房间数量*/
@property(nonatomic,strong)UILabel * totleCountLabel;


/** HourIMG*/
@property(nonatomic,strong)NSString *HourIMG;

/** HourIMG*/
@property(nonatomic,strong)NSString *HourName;

/** HourIMG*/
@property(nonatomic,strong)NSString *Hourid;

/** HourIMG*/
@property(nonatomic,strong)NSString *WaiterIMG;

/** HourIMG*/
@property(nonatomic,strong)NSString *WaiterName;

/** HourIMG*/
@property(nonatomic,strong)NSString *WaiterID;


/** HourIMG*/
@property(nonatomic,strong)NSString *openid;

@end

@implementation MSCaiwuController

- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    self.RoomManagementArray = [NSMutableArray new];
    //    self.RoomArray = [NSMutableArray new];
    
    Prepare *header = [Prepare headerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiHeaderRefresh)];
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    // 马上进入刷新状态
    self.CollectionView.mj_header = header;
    [self.CollectionView.mj_header beginRefreshing];
}
- (void)MJChiBaoZiHeaderRefresh{
    page = 1;
    [self ReloadData];
    
}
- (void)MJChiBaoZiFootderRefresh{
    if (count / pageSize < page) {
        [MBManager showBriefAlert:@"没有更多数据了"];
    }else{
        page++;
    }
    
    [self FootderRefreshReloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self CreatCollectionHeaderView];
    
    
    [self CreateNavigationBar];
    
    [self CreatCollectionView];
    
    PrepareFooter *footder = [PrepareFooter footerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiFootderRefresh)];
    // 马上进入刷新状态
    self.CollectionView.mj_footer = footder;
}
- (void)ReloadData{
    [self.RoomManagementArray removeAllObjects];
    //    [self.RoomArray removeAllObjects];
    self.RoomArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"CaiwuDictionary"];
    //    WYCLog(@"arrarrarrarr-------%@",self.RoomArray);
    
    
    NSDictionary * params = @{@"busid":[WYCAccountTool unarchivebelongBusid],@"uid":[WYCAccountTool unarchiveuid],@"type":@"4",@"page":@(page),@"pageSize":@(pageSize)};
    //    WYCLog(@"responseObject---------%@",params);
    [HTTPRequest POST:MSqueryRoomInformation params:params succeed:^(id responseObject) {
                WYCLog(@"responseObject---------%@",responseObject);
        if (CodeStr) {
            [self.CollectionView.mj_header endRefreshing];
            count = [responseObject[@"data"][@"count"] integerValue];
            self.totleCountLabel.text = [NSString stringWithFormat:@"房间总量:%@间     开房量:%@间",responseObject[@"data"][@"count"],responseObject[@"data"][@"roomOpenSize"]];
            
            
            NSMutableArray *temporaryArray = [NSMutableArray new];
            for (NSDictionary * dict in responseObject[@"data"][@"roomRuningList"]) {
                MSRoomManageMentModel * model = [MSRoomManageMentModel mj_objectWithKeyValues:dict];
                [temporaryArray addObject:model];
                self.RoomManagementArray =  temporaryArray;
                
                
                for (NSDictionary * dicR in model.RoomArray) {
                    model.WaiterModel = [MSWaiterModel mj_objectWithKeyValues:dicR];
                    [model.waiter addObject:model.WaiterModel];
                }
                
                for (NSDictionary * dic in model.waiter) {
                    model.WaiterModel = [MSWaiterModel mj_objectWithKeyValues:dic];
                    [model.waiter addObject:model.WaiterModel];
                }
            }
        }else{
            [self.CollectionView.mj_header endRefreshing];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            page = [params[@"page"] integerValue];
        }
        [self.CollectionView reloadData];
    } failure:^(NSError *error) {
        [self.CollectionView.mj_header endRefreshing];
        [MBManager showBriefAlert:Failed];
    }];
}
- (void)FootderRefreshReloadData{
    [self.RoomManagementArray removeAllObjects];
    self.RoomArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"CaiwuDictionary"];
    
    
    NSDictionary * params = @{@"busid":[WYCAccountTool unarchivebelongBusid],@"uid":[WYCAccountTool unarchiveuid],@"type":@"4",@"page":@(page),@"pageSize":@(pageSize)};
    //    WYCLog(@"responseObject---------%@",params);
    [HTTPRequest POST:MSqueryRoomInformation params:params succeed:^(id responseObject) {
        WYCLog(@"responseObject---------%@",responseObject);
        if (CodeStr) {
            [self.CollectionView.mj_footer endRefreshing];
            self.totleCountLabel.text = [NSString stringWithFormat:@"房间总量:%@间     开房量:%@间",responseObject[@"data"][@"count"],responseObject[@"data"][@"roomOpenSize"]];
            
            
            NSMutableArray *temporaryArray = [NSMutableArray new];
            for (NSDictionary * dict in responseObject[@"data"][@"roomRuningList"]) {
                MSRoomManageMentModel * model = [MSRoomManageMentModel mj_objectWithKeyValues:dict];
                [self.RoomManagementArray addObject:model];
                
                
                for (NSDictionary * dicR in model.RoomArray) {
                    model.WaiterModel = [MSWaiterModel mj_objectWithKeyValues:dicR];
                    [model.waiter addObject:model.WaiterModel];
                }
                
                for (NSDictionary * dic in model.waiter) {
                    model.WaiterModel = [MSWaiterModel mj_objectWithKeyValues:dic];
                    [model.waiter addObject:model.WaiterModel];
                }
            }
        }else{
            [self.CollectionView.mj_footer endRefreshing];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            page --;
        }
        [self.CollectionView reloadData];
    } failure:^(NSError *error) {
        [self.CollectionView.mj_footer endRefreshing];
        [MBManager showBriefAlert:Failed];
    }];
}
- (void)CreatCollectionHeaderView{
    
    UIView * HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, 300 * px)];
    HeaderView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:HeaderView];
    //    self.CollectionHeaderView = HeaderView;
    
    /** 房间总量*/
    UILabel * totleCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, 40 * px, ScreenWidth / 3 * 2, 80 * px)];
    totleCountLabel.textColor = [UIColor whiteColor];
    totleCountLabel.text = @"房间总量:70间     开房量:50间";
    totleCountLabel.textAlignment = NSTextAlignmentLeft;
    totleCountLabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
    [HeaderView addSubview:totleCountLabel];
    self.totleCountLabel = totleCountLabel;
    
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(totleCountLabel.frame) + 40 * px, ScreenWidth, 1)];
    lineView.backgroundColor = BackViewColor;
    [HeaderView addSubview:lineView];
    
    
    /** 开房标记*/
    UIImageView * GetroomIMG = [[UIImageView alloc] initWithFrame:CGRectMake(30 * px, CGRectGetMaxY(lineView.frame) + 60 * px, 30 * px, 30 * px)];
    GetroomIMG.backgroundColor = WYCRGBColor(122, 106, 224);
    GetroomIMG.layer.cornerRadius = 10 * px;
    [HeaderView addSubview:GetroomIMG];
    
    /** 开房label*/
    UILabel * Getroomlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(GetroomIMG.frame) + 5 * px, GetroomIMG.y - 20 * px, 200 * px, 60 * px)];
    Getroomlabel.textColor = WYCRGBColor(126, 138, 155);
    Getroomlabel.text = @"开房";
    Getroomlabel.font = [UIFont systemFontOfSize:SYRealValue(25 / 2)];
    [HeaderView addSubview:Getroomlabel];
    
    
    
    /** 预约标记*/
    UIImageView * AppointmentIMG = [[UIImageView alloc] initWithFrame:CGRectMake(HeaderView.width / 4, GetroomIMG.y, GetroomIMG.width, GetroomIMG.height)];
    AppointmentIMG.backgroundColor = WYCRGBColor(97, 203, 183);
    AppointmentIMG.layer.cornerRadius = 10 * px;
    [HeaderView addSubview:AppointmentIMG];
    
    /** 预约label*/
    UILabel * Appointmentlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(AppointmentIMG.frame) + 5 * px, Getroomlabel.y, 200 * px, 60 * px)];
    Appointmentlabel.textColor = Getroomlabel.textColor;
    Appointmentlabel.text = @"预约";
    Appointmentlabel.font = [UIFont systemFontOfSize:SYRealValue(25 / 2)];
    [HeaderView addSubview:Appointmentlabel];
    
    
    /** 超消费标记*/
    UIImageView * OverConsumptionIMG = [[UIImageView alloc] initWithFrame:CGRectMake(HeaderView.width / 2, GetroomIMG.y, GetroomIMG.width, GetroomIMG.height)];
    OverConsumptionIMG.backgroundColor = WYCRGBColor(224, 93, 49);
    OverConsumptionIMG.layer.cornerRadius = 10 * px;
    [HeaderView addSubview:OverConsumptionIMG];
    
    /** 超消费label*/
    UILabel * OverConsumptionlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(OverConsumptionIMG.frame) + 5 * px, Getroomlabel.y, 200 * px, 60 * px)];
    OverConsumptionlabel.textColor = Getroomlabel.textColor;
    OverConsumptionlabel.text = @"超消费";
    OverConsumptionlabel.font = [UIFont systemFontOfSize:SYRealValue(25 / 2)];
    [HeaderView addSubview:OverConsumptionlabel];
    
    
    
    
    /** 未使用标记*/
    UIImageView * NotusedIMG = [[UIImageView alloc] initWithFrame:CGRectMake(HeaderView.width / 4 * 3, GetroomIMG.y, GetroomIMG.width, GetroomIMG.height)];
    NotusedIMG.backgroundColor = WYCRGBColor(144, 134, 159);
    NotusedIMG.layer.cornerRadius = 10 * px;
    [HeaderView addSubview:NotusedIMG];
    
    /** 招待label*/
    UILabel * Notusedlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NotusedIMG.frame) + 5 * px, Getroomlabel.y, 200 * px, 60 * px)];
    Notusedlabel.textColor = Getroomlabel.textColor;
    Notusedlabel.text = @"未使用";
    Notusedlabel.font = [UIFont systemFontOfSize:SYRealValue(25 / 2)];
    [HeaderView addSubview:Notusedlabel];
    
    
//    UITextField * seachField = [[UITextField alloc] initWithFrame:CGRectMake(Getroomlabel.x, CGRectGetMaxY(Getroomlabel.frame) + 30 * px, HeaderView.width - Getroomlabel.x * 2, 120 * px)];
//    seachField.placeholder = @"搜索房间号";
//    seachField.layer.cornerRadius = 10 * px;
//    seachField.keyboardType = UIKeyboardTypeNumberPad;
//    seachField.backgroundColor = BackViewColor;
//    [seachField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
//    [seachField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
//    seachField.textColor = [UIColor whiteColor];
//    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"搜索"]];
//    imgView.frame = CGRectMake(20 * px, 30 * px, 60 * px, 60 * px);
//    seachField.leftView = imgView;
//    seachField.leftViewMode = UITextFieldViewModeAlways;
//    [HeaderView addSubview:seachField];
    
}

- (void)CreatCollectionView{
    
    //1.初始化layout
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置collectionView滚动方向
    //
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    //设置headerView的尺寸大小
    layout.headerReferenceSize = CGSizeMake(ScreenWidth, self.CollectionHeaderView.height);
    //该方法也可以设置itemSize
    //    layout.itemSize = CGSizeMake(744 * px, 438 * px);
    //2.初始化collectionView
    self.CollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, [self navBarBottom] + 320 * px, ScreenWidth, ScreenHeight - [self navBarBottom] - 320 * px) collectionViewLayout:layout];
    
    
    self.CollectionView.backgroundColor = [UIColor clearColor];
    //3.注册collectionViewCell //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [self.CollectionView registerClass:[MSBindingRelationsCell class] forCellWithReuseIdentifier:cellId];
    //注册headerView 此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为reusableView
    [self.CollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerId];
    
    self.CollectionView.showsVerticalScrollIndicator = NO;
    //4.设置代理
    self.CollectionView.delegate = self;
    
    self.CollectionView.dataSource = self;
    
    [self.view addSubview:self.CollectionView];
}

#pragma mark collectionView代理方法
//返回section个
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
    
}
//设置每个分区的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.RoomManagementArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    MSBindingRelationsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    
    [cell setNeedsLayout];
    
    
    
    cell.SettlementButtonDelegate = self;
    [cell.SettlementButton addTarget:self action:@selector(SettlementButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.OpenRoomButton addTarget:self action:@selector(OpenRoomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    if(self.RoomManagementArray.count > indexPath.row){
        cell.RoomManageMentModel = self.RoomManagementArray[indexPath.row];
    }
    //    cell.MyModel = self.RoomArray[indexPath.row];
    id objectroom_amount = [self.RoomArray objectForKey:@"room_amount"];
    if ([objectroom_amount[@"pma_isShow"] intValue] != 0) {
        cell.CurrentConsumptionLabel.hidden = YES;
    }else{
        cell.CurrentConsumptionLabel.hidden = NO;
    }
    if ([cell.RoomManageMentModel.roomState isEqualToString:@"0"]) {
        //
        cell.StateIMG.image = [UIImage imageNamed:@"weishiyong"];
        cell.RoomBackView.backgroundColor = BackViewColor;
        cell.backView.layer.borderColor = BackViewColor.CGColor;
        id objectroom_open = [self.RoomArray objectForKey:@"room_open"];
        
        id objectroom_reserve= [self.RoomArray objectForKey:@"room_reserve"];
        
        if ([objectroom_open[@"pma_isShow"] intValue] == 0) {
            //            objectroom_open
            [cell.SettlementButton setTitle:@"开房" forState:UIControlStateNormal];
            cell.SettlementButton.hidden = NO;
        }else{
            cell.SettlementButton.hidden = YES;
        }
        
        if ([objectroom_reserve[@"pma_isShow"] intValue] == 0) {
            //            objectroom_reserve
            [cell.OpenRoomButton setTitle:@"预约" forState:UIControlStateNormal];
            cell.OpenRoomButton.hidden = NO;
        }else{
            cell.OpenRoomButton.hidden = YES;
        }
        
        
        //        id objectValue = [self.RoomArray objectForKey:@"room_open"];
        
        
        
    }else if ([cell.RoomManageMentModel.roomState isEqualToString:@"2"]) {
        cell.StateIMG.image = [UIImage imageNamed:@"yuding"];
        cell.RoomBackView.backgroundColor = WYCRGBColor(39, 77, 90);
        cell.backView.layer.borderColor = WYCRGBColor(39, 77, 90).CGColor;
        
        id objectroom_open = [self.RoomArray objectForKey:@"room_open"];
        
        id objectroom_reserve = [self.RoomArray objectForKey:@"room_checkout"];
        if ([objectroom_open[@"pma_isShow"] intValue] == 0) {
            //            objectroom_open
            [cell.SettlementButton setTitle:@"开房" forState:UIControlStateNormal];
            cell.SettlementButton.hidden = NO;
        }else{
            cell.SettlementButton.hidden = YES;
        }
        
        if ([objectroom_reserve[@"pma_isShow"] intValue] == 0) {
            //            objectroom_reserve
            [cell.OpenRoomButton setTitle:@"退房" forState:UIControlStateNormal];
            cell.OpenRoomButton.hidden = NO;
        }else{
            cell.OpenRoomButton.hidden = YES;
        }
        
    }else if ([cell.RoomManageMentModel.roomState isEqualToString:@"1"]) {
        cell.StateIMG.image = [UIImage imageNamed:@"kaifang"];
        cell.RoomBackView.backgroundColor = WYCRGBColor(54, 55, 96);
        cell.backView.layer.borderColor = WYCRGBColor(54, 55, 96).CGColor;
        
        id objectroom_bindprincess = [self.RoomArray objectForKey:@"room_bindprincess"];
        
        id objectroom_close = [self.RoomArray objectForKey:@"room_close"];
        
        if ([objectroom_bindprincess[@"pma_isShow"] intValue] == 0) {
            //            objectroom_open
            [cell.SettlementButton setTitle:@"绑定公关" forState:UIControlStateNormal];
            cell.SettlementButton.hidden = NO;
        }else{
            cell.SettlementButton.hidden = YES;
        }
        
        if ([objectroom_close[@"pma_isShow"] intValue] == 0) {
            //            objectroom_reserve
            [cell.OpenRoomButton setTitle:@"结算" forState:UIControlStateNormal];
            cell.OpenRoomButton.hidden = NO;
        }else{
            id objectroom_exchange = [self.RoomArray objectForKey:@"room_exchange"];
            if ([objectroom_exchange[@"pma_isShow"] intValue] == 0) {
                [cell.OpenRoomButton setTitle:@"换房" forState:UIControlStateNormal];
                cell.OpenRoomButton.hidden = NO;
                
            }else{
                cell.OpenRoomButton.hidden = YES;
            }
        }
        
    }else {
        cell.StateIMG.image = [UIImage imageNamed:@"chaoxiaofei"];
        cell.RoomBackView.backgroundColor = WYCRGBColor(69, 55, 63);
        cell.backView.layer.borderColor = WYCRGBColor(75, 60, 53).CGColor;
        id objectroom_open = [self.RoomArray objectForKey:@"room_bindprincess"];
        
        id objectroom_reserve = [self.RoomArray objectForKey:@"room_close"];
        
        if ([objectroom_open[@"pma_isShow"] intValue] == 0) {
            //            objectroom_open
            [cell.SettlementButton setTitle:@"绑定公关" forState:UIControlStateNormal];
            cell.SettlementButton.hidden = NO;
        }else{
            cell.SettlementButton.hidden = YES;
        }
        
        if ([objectroom_reserve[@"pma_isShow"] intValue] == 0) {
            //            objectroom_reserve
            [cell.OpenRoomButton setTitle:@"结算" forState:UIControlStateNormal];
            cell.OpenRoomButton.hidden = NO;
        }else{
            id objectroom_exchange = [self.RoomArray objectForKey:@"room_exchange"];
            if ([objectroom_exchange[@"pma_isShow"] intValue] == 0) {
                [cell.OpenRoomButton setTitle:@"换房" forState:UIControlStateNormal];
                cell.OpenRoomButton.hidden = NO;
            }else{
                cell.OpenRoomButton.hidden = YES;
            }
        }
    }
    if (cell.OpenRoomButton.hidden == YES) {
        cell.SettlementButton.frame = CGRectMake(cell.backView.width / 3, cell.backView.height - 80 * px, cell.backView.width / 3, 60 * px);
    }else{
        cell.SettlementButton.frame = CGRectMake(20 * px, CGRectGetMaxY(cell.RelationsView.frame), cell.backView.width / 2 - 40 * px , 60 * px);
    }
    
    if (cell.SettlementButton.hidden == YES) {
        cell.OpenRoomButton.frame = CGRectMake(cell.backView.width / 3, cell.backView.height - 80 * px, cell.backView.width / 3, 60 * px);
    }else{
        cell.OpenRoomButton.frame = CGRectMake(cell.backView.width / 2 + 20 * px, CGRectGetMaxY(cell.RelationsView.frame), cell.SettlementButton.width, cell.SettlementButton.height);
    }
    return cell;
    
}
- (void)ClickSettlementButtonUid:(NSString *)UID Roomid:(NSString *)Roomid RoomName:(NSString *)RoomName RoomMoney:(NSString *)RoomMoney HourIMG:(NSString *)HourIMG HourName:(NSString *)HourName Hourid:(NSString *)Hourid WaiterIMG:(NSString *)WaiterIMG WaiterName:(NSString *)WaiterName WaiterID:(NSString *)WaiterID openid:(nonnull NSString *)openid{
    
    
    self.roomid = Roomid;
    self.RoomName = RoomName;
    self.RoomMoney = RoomMoney;
    self.HourIMG = HourIMG;
    self.HourName = HourName;
    self.Hourid = Hourid;
    self.WaiterIMG = WaiterIMG;
    self.WaiterName = WaiterName;
    self.WaiterID = WaiterID;
    self.openid = openid;
    
    WYCLog(@"------%@",self.openid);
    
    
}
//- (void)ClickSettlementButtonUid:(NSString *)UID Roomid:(NSString *)Roomid RoomName:(NSString *)RoomName RoomMoney:(nonnull NSString *)RoomMoney
//{
//
//}
- (void)SettlementButtonClick:(UIButton *)sender{
    
    if ([sender.titleLabel.text isEqualToString:@"绑定公关"]) {
        UIView * view = [[UIView alloc] init];
        view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [[UIApplication sharedApplication].keyWindow  addSubview:view];
        self.backView = view;
        
        
        UIView * showView = [[UIView alloc] init];
        showView.frame = CGRectMake(100 * px, ScreenHeight / 2, ScreenWidth - 200 * px, ScreenHeight / 4);
        showView.backgroundColor = [UIColor whiteColor];
        showView.layer.cornerRadius = 20 * px;
        [view addSubview:showView];
        self.showView = showView;
        
        UIView * centerView = [[UIView alloc] initWithFrame:CGRectMake(100 * px, 100 * px, showView.width - 200 * px, showView.height - 200 * px)];
        centerView.backgroundColor = [UIColor clearColor];
        [showView addSubview:centerView];
        
        /** 关闭*/
        UIButton * closeButton = [[UIButton alloc] initWithFrame:CGRectMake(showView.width - 80 * px, 20 * px, 60 * px, 60 * px)];
        [closeButton  setImage:[UIImage imageNamed:@"pop_dis"] forState:UIControlStateNormal];
        [closeButton  addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [showView  addSubview:closeButton];
        
        
        
        CGFloat titleButtonW = centerView.width;
        CGFloat titleButtonX = 0;
        CGFloat titleButtonH = centerView.height / 2 - 20 * px;
        NSArray * titleArray = @[@"扫码绑定",@"其他绑定方式"];
        for (int i = 0;i < titleArray.count; i ++) {
            /** 点击*/
            UIButton * titleButton = [[UIButton alloc] initWithFrame:CGRectMake(titleButtonX, (titleButtonH + 20 * px) * i, titleButtonW, titleButtonH)];
            
            titleButton.tag = i;
            //            titleButton.layer.borderColor = FontColor.CGColor;
            //            titleButton.layer.borderWidth = 1;
            [titleButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
            titleButton.layer.cornerRadius = titleButtonH * 0.5;
            titleButton.layer.masksToBounds = YES;
            [titleButton setTitle:titleArray[i] forState:UIControlStateNormal];
            titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            titleButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
            [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [titleButton addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            [centerView addSubview:titleButton];
        }
    }else if ([sender.titleLabel.text isEqualToString:@"结算"]){
        
        WYCLogFunc;
        MSFinancialRoomManagementController *RoomManagementVC = [[MSFinancialRoomManagementController alloc] init];
        RoomManagementVC.roomName = self.RoomName;
        RoomManagementVC.roomid = self.roomid;
        RoomManagementVC.openid = self.openid;
        [self.navigationController pushViewController:RoomManagementVC animated:NO];
        
        
    }else if ([sender.titleLabel.text isEqualToString:@"预约"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else if ([sender.titleLabel.text isEqualToString:@"开房"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.RID = self.Hourid;
        SetRoomManagementVC.RName = self.HourName;
        SetRoomManagementVC.RPhoto = self.HourIMG;
        SetRoomManagementVC.WID = self.WaiterID;
        SetRoomManagementVC.WName = self.WaiterName;
        SetRoomManagementVC.WPhoto = self.WaiterIMG;
        
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else if ([sender.titleLabel.text isEqualToString:@"换房"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else {
        //        [MBManager showBriefAlert:@"退房"];
        NSDictionary * params = @{@"roomId":self.roomid,@"waiterUid":@"",@"openRoomUid":@"0",@"roomState":@4,@"changeRoomId":@0};
        //        WYCLog(@"params:%@",params);
        [HTTPRequest POST:MSupdateRoomState params:params succeed:^(id responseObject) {
            if (CodeStr) {
                [MBManager showBriefAlert:responseObject[@"msg"]];
                [self ReloadData];
            }else{
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
        } failure:^(NSError *error) {
            [MBManager showBriefAlert:Failed];
            //            WYCLog(@"error:%@",error);
        }];
        
    }
    
    
    
    
}

- (void)titleButtonClick:(UIButton *)sender{
    if (sender.tag == 0) {
        [self.backView removeFromSuperview];
        ScanningViewController * saomiaoVC = [[ScanningViewController alloc] init];
        saomiaoVC.roomid = self.roomid;
        [self.navigationController pushViewController:saomiaoVC animated:NO];
    }else{
        [self.backView removeFromSuperview];
        MSQueryRelationsController * QueryRelationsVC = [[MSQueryRelationsController alloc] init];
        QueryRelationsVC.roomid = self.roomid;
        [self.navigationController pushViewController:QueryRelationsVC animated:NO];
    }
    
}
- (void)closeButtonClick{
    [self.backView removeFromSuperview];
    
}
- (void)OpenRoomButtonClick:(UIButton *)sender{
    if ([sender.titleLabel.text isEqualToString:@"绑定公关"]) {
        UIView * view = [[UIView alloc] init];
        view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [[UIApplication sharedApplication].keyWindow  addSubview:view];
        self.backView = view;
        
        
        UIView * showView = [[UIView alloc] init];
        showView.frame = CGRectMake(100 * px, ScreenHeight / 2, ScreenWidth - 200 * px, ScreenHeight / 4);
        showView.backgroundColor = [UIColor whiteColor];
        showView.layer.cornerRadius = 20 * px;
        [view addSubview:showView];
        self.showView = showView;
        
        UIView * centerView = [[UIView alloc] initWithFrame:CGRectMake(100 * px, 100 * px, showView.width - 200 * px, showView.height - 200 * px)];
        centerView.backgroundColor = [UIColor clearColor];
        [showView addSubview:centerView];
        
        /** 关闭*/
        UIButton * closeButton = [[UIButton alloc] initWithFrame:CGRectMake(showView.width - 80 * px, 20 * px, 60 * px, 60 * px)];
        [closeButton  setImage:[UIImage imageNamed:@"pop_dis"] forState:UIControlStateNormal];
        [closeButton  addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [showView  addSubview:closeButton];
        
        
        
        CGFloat titleButtonW = centerView.width;
        CGFloat titleButtonX = 0;
        CGFloat titleButtonH = centerView.height / 2 - 20 * px;
        NSArray * titleArray = @[@"扫码绑定",@"其他绑定方式"];
        for (int i = 0;i < titleArray.count; i ++) {
            /** 点击*/
            UIButton * titleButton = [[UIButton alloc] initWithFrame:CGRectMake(titleButtonX, (titleButtonH + 20 * px) * i, titleButtonW, titleButtonH)];
            
            titleButton.tag = i;
            //            titleButton.layer.borderColor = FontColor.CGColor;
            //            titleButton.layer.borderWidth = 1;
            [titleButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
            titleButton.layer.cornerRadius = titleButtonH * 0.5;
            titleButton.layer.masksToBounds = YES;
            [titleButton setTitle:titleArray[i] forState:UIControlStateNormal];
            titleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            titleButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
            [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [titleButton addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            [centerView addSubview:titleButton];
        }
    }else if ([sender.titleLabel.text isEqualToString:@"结算"]){
        
        WYCLogFunc;
        MSFinancialRoomManagementController *RoomManagementVC = [[MSFinancialRoomManagementController alloc] init];
        RoomManagementVC.roomName = self.RoomName;
        RoomManagementVC.roomid = self.roomid;
        RoomManagementVC.openid = self.openid;
        [self.navigationController pushViewController:RoomManagementVC animated:NO];
        
        
    }else if ([sender.titleLabel.text isEqualToString:@"预约"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else if ([sender.titleLabel.text isEqualToString:@"开房"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.RID = self.Hourid;
        SetRoomManagementVC.RName = self.HourName;
        SetRoomManagementVC.RPhoto = self.HourIMG;
        SetRoomManagementVC.WID = self.WaiterID;
        SetRoomManagementVC.WName = self.WaiterName;
        SetRoomManagementVC.WPhoto = self.WaiterIMG;
        
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else if ([sender.titleLabel.text isEqualToString:@"换房"]){
        MSSetRoomManagementController *SetRoomManagementVC = [[MSSetRoomManagementController alloc] init];
        SetRoomManagementVC.tagStr = sender.titleLabel.text;
        SetRoomManagementVC.roomid = self.roomid;
        SetRoomManagementVC.roomMoney = self.RoomMoney;
        SetRoomManagementVC.RID = self.Hourid;
        SetRoomManagementVC.RName = self.HourName;
        SetRoomManagementVC.RPhoto = self.HourIMG;
        SetRoomManagementVC.WID = self.WaiterID;
        SetRoomManagementVC.WName = self.WaiterName;
        SetRoomManagementVC.WPhoto = self.WaiterIMG;
        
        SetRoomManagementVC.roomName = self.RoomName;
        [self.navigationController pushViewController:SetRoomManagementVC animated:NO];
        
    }else {
        //        [MBManager showBriefAlert:@"退房"];
        NSDictionary * params = @{@"roomId":self.roomid,@"waiterUid":@"",@"openRoomUid":@"0",@"roomState":@4,@"changeRoomId":@0};
        //        WYCLog(@"params:%@",params);
        [HTTPRequest POST:MSupdateRoomState params:params succeed:^(id responseObject) {
            if (CodeStr) {
                [MBManager showBriefAlert:responseObject[@"msg"]];
                [self ReloadData];
            }else{
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
        } failure:^(NSError *error) {
            [MBManager showBriefAlert:Failed];
            //            WYCLog(@"error:%@",error);
        }];
        
    }
    
    
    
}
//设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(ScreenWidth / 2 - 10 * px, 700 * px);
    
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 10 * px;
    
}
//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 20 * px;
    
}


#pragma mark -UICollectionViewDelegate
//UICollectionView被选中的时候调用
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%zd",indexPath.item);
    id objectroom_amount = [self.RoomArray objectForKey:@"room_amount"];
    //    if ([objectroom_amount[@"pma_isShow"] intValue] != 0) {
    //        cell.CurrentConsumptionLabel.hidden = YES;
    //    }else{
    //        cell.CurrentConsumptionLabel.hidden = NO;
    //    }
    //    id objectroom_open = [self.RoomArray objectForKey:@"room_open"];
    
    //    id objectroom_reserve= [self.RoomArray objectForKey:@"room_reserve"];
    MSRoomManageMentModel * roomModel = self.RoomManagementArray[indexPath.row];
    MSRoomConsumptionController * consumtionVC = [[MSRoomConsumptionController alloc] init];
    consumtionVC.roomID = roomModel.roomId;
    [self.navigationController pushViewController:consumtionVC animated:NO];
    
    
    
}
// 返回这个UICollectionView是否可以被选择
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
    
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"房间管理";
    naviagtionBar.rightBtn.hidden = YES;
//    naviagtionBar.leftBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
@end
